//登录
async function login(){
	var data = await Ajax('GET', 'http://39.105.192.164:9090/apitest/getuser', '');
	//console.log(data)
//	console.log(JSON.parse(data).data);
	render(JSON.parse(data).data)
}

function render(json){
	var username = document.getElementById('username').value;
	var password = document.getElementById('password').value;
	console.log(username);
	
    json.forEach(function(item){
    	//console.log(item.username);
    	//console.log(item.password);
//  	if(item.username == username){
//  		console.log("成功")
//  	}
      	if((item.username == username)&& (item.password == password)){
    	 	console.log("登录成功");
    	}
    })
}


//用async的方式执行的注册
async function save(){
	var username = document.getElementById('username');
	var password = document.getElementById('password');
	var data2 = await Ajax('POST', 'http://39.105.192.164:9090/apitest/adduser', `username=${username.value}&password=${password.value}`);
	//console.log(data);
	if(JSON.parse(data2).code == 1){
		//location.reload();
		console.log("注册成功");
	}
}
//注册
//function save(){
//	var username = document.getElementById('username');
//	var password = document.getElementById('password');
//	var data2 = Ajax('POST', 'http://39.105.192.164:9090/apitest/adduser', `username=${username.value}&password=${password.value}`);
//	console.log(data2);
//	
////	if(JSON.parse(data2).code == 1){
////		//location.reload();
////		console.log("注册成功");
////	}
//}